/*------------------------------------------------------------------------------
 * PROJ : Prototype
 * NAME : sculove.spring.framework.util.AuthUtil.java
 *        
 * Copyright 2009 sculove All rights reserved
 *------------------------------------------------------------------------------
*/
package sculove.spring.framework.util;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import sculove.spring.zzz.login.model.UserDTO;

/**
 * <pre>
 * sculove.spring.framework.util.AuthUtil.java
 * 권한과 관련된 Util
 * 
 * </pre>
 * @date : 2009. 12. 4. 오후 6:14:38
 * @version :
 * @author : sculove
 */
public class AuthUtil {
	/**
	 * 로그인 세션이 존재할 경우 성공
	 * @param request
	 * @return
	 */
	public static boolean hasSession(HttpServletRequest request) {
		return SStringUtil.hasText(SessionUtil.getString(request, "userId"));
	}

	/**
	 * 로그인 세션 생성
	 * @param request
	 * @param dto 
	 */
	public static void setSession(HttpServletRequest request, UserDTO dto) {
		SessionUtil.set(request, "userId", "sculove");
		SessionUtil.set(request, "userName", "손찬욱");	
	}
	
	/**
	 * 로그인 세션 삭제
	 * @param request
	 */
	public static void removeSession(HttpServletRequest request) {
		SessionUtil.removeAll(request);	
	}
	
	/* 
	 * @return 요청한 URL이 무조건 통과되는 URL인 경우 true
	 */
	public static boolean isPassURL(String URL) {
		String path = SStringUtil.unqualify(URL, '/');
		List<String> list = Configuration.getXmlInstance().getList("servlet.isPassURL.url");
		for(String url : list) {
			if(path.equals(url)) return true;
		}
		return false;
	}
}
